package cate.game.activity.luckybag;

import cate.game.activity.base.core.SubActivitySingle;
import cate.game.res.MixRes;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

public class LuckyBagPo extends SubActivitySingle<LuckyBagActivity> {
    @NoteField("key:福袋位置，value:奖励id")
    public Map<Integer, Integer> rewardMap;
    @NoteField(value = "这层累计开福袋次数", detail = "用于保底")
    @JsonIgnore
    public int drawTimes;
    @NoteField("本轮是否已开")
    public boolean isDrawn;

    @Override
    public void initialize(LuckyBagActivity parent) {
        super.initialize(parent);
        if (rewardMap == null) {
            rewardMap = new HashMap<>();
        }
    }

    public void reset() {
        rewardMap.clear();
        isDrawn = false;
    }

    public void setReward(int pos, int id) {
        rewardMap.put(pos, id);
        isDrawn = true;
    }

    public MixRes createReward() {
        MixRes reward = new MixRes();
        rewardMap.values().stream().map(id -> parent.findRewardRow(id)).forEach(row -> reward.addList(new MixRes(row.reward)));
        return reward;
    }
}
